package com.ruoyi.easyExcelHandler.excelStyle;

import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;

public class HandlerStyleWrite {


    public static HorizontalCellStyleStrategy getHorizontalCellStyleStrategy() {
        // 头的策略
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 背景设置为白色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.index);
        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        //边框
        headWriteCellStyle.setBorderBottom(BorderStyle.THIN);
        headWriteCellStyle.setBorderLeft(BorderStyle.THIN);
        headWriteCellStyle.setBorderRight(BorderStyle.THIN);
        headWriteCellStyle.setBorderTop(BorderStyle.THIN);
        //自动换行
        headWriteCellStyle.setWrapped(true);
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setBold(true);
        headWriteFont.setFontName("宋体");
        headWriteFont.setFontHeightInPoints((short)10);
        headWriteCellStyle.setWriteFont(headWriteFont);
        // // 内容的策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        // // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
        // contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        // // 背景绿色
        // contentWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
        // contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        // contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        // //边框
        // contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
        // contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
        // contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
        // contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
        // //自动换行
        // contentWriteCellStyle.setWrapped(true);
        // //文字
        // WriteFont contentWriteFont = new WriteFont();
        // // 字体大小
        // contentWriteFont.setFontHeightInPoints((short)12);
        // contentWriteFont.setFontName("宋体");
        // contentWriteCellStyle.setWriteFont(contentWriteFont);
        // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
        return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
    }


}
